ATG Shipping Groups, methods and calculators

Adding shipping information to shopping carts involves the following sub-processes:
1) Creating a list of shipping groups for potential use in the current order
2) Specifying the shipping groups to use with the current order
3) Selecting the shipping methods, such as Ground or Next Day, for the order’s shipping groups 


What is Shipping Group?
A ShippingGroup contains information on the shipping address and delivery method for a group of commerce items. 

By default, a new Order has one defaultShippingGroup. As items are added to the Order, these items automatically become part of the default ShippingGroup. Once a second ShippingGroup is added to theOrder, all the items in the Order are removed from the default ShippingGroup and must be explicitly added to one of two shipping groups. 
 
How to create new Shipping Groups?
You can create a list of shipping groups for potential use in an Order in one of two ways:
  • from information gathered from the user via forms

  • from information stored in the user’s profile
 Below two form handlers allow user to add new shipping groups  
  • /atg/commerce/order/purchase/CreateHardgoodShippingGroupFormHandler
  • /atg/commerce/order/purchase/CreateElectronicShippingGroupFormHandler
 Both extends PurchaseProcessFormHandler 

How to add Shipping Group to an Order?
Steps:
1) Create Shipping Group
2) Make any changes to the Shipping Group, such as setting the address
3) Add the Shipping Group to the Order


 Here is the code snippet:
// Get a reference to the OrderManager 
OrderManager orderManager = (OrderManager)   request.resolveName("/atg/commerce/order/OrderManager");  
// Create the ShippingGroup 
ShippingGroup shippingGroup shippingGroupManager.createShippingGroup(); 
// Add the ShippingGroup to the Order shippingGroup.addShippingGroupToOrder(pOrder, shippingGroup);

How to find available Shipping methods for a particular Shipping Group?
Use droplet  /atg/commerce/pricing/AvailableShippingMethods


How to initiate Shipping group from Profile?
Use droplet /atg/commerce/order/purchase/ShippingGroupDroplet
 
What is Shipping method? 
Each Shipping method is represented by ShippingCalculator component class.

Shipping methods examples are:
  • Ground
  • 2 day delivery
  • Overnight
  • Calculate Shipping price based on couriers web service
  • etc...
Different types of Shipping calculators are:
  • FixedPriceShippingCalculator - Flat rate for shipping
            Ex: Ground shipping is always $15
  • PriceRangeShippingCalculator - Define shipping price based price range
             Ex: $0 - $50  ($5)
                   $51 - $100  ($10)
                   $101 - $1000  (FREE)
  • WeightRangeShippingCalculator - Weight Property added at SKU level and price set based on weight
  • PropertyRangeShippingCalculator - Shipping price decided Based on SKU property
          Ex: Volume
    How to Filter Shipping methods?
    In few scenarios, All shipping methods should not be available. To limit shipping methods developer can sub-class Shipping calculator and override the getAvailableMethods().

    Ex: Courier shipping not allowed for PO boxes

    How to write custom shipping calculator?
    Here are the steps:
    1. Create a new custom calculator component 
    /com/commerce/shipping/FixedPriceServiceCaclulator.properties 
    $class=com.xxx.commerce.pricing.calculators.FixedPriceShippingCalculator
    # name of shipping method
    shippingMethod=DEMO
    # costs 
    amount=10.0

    2. Create a custom Java class and this should extends the shippingCalculatorImpl class
    ShippingCalculatorImpl class have two method for override.
    1.getAmount()  - calculate the shipping price

    2.getAvailableMethods()  - Used to restrict your custom shipping method

    public class FixedPriceShippingCalculator extends ShippingCalculatorImpl { 

    protected double getAmount(Order order, ShippingPriceInfo priceQuote, ShippingGroup shippingGroup, RepositoryItem pricingModel, Locale locale, RepositoryItem profile, Map extraParameters) throws PricingException { }

    public void getAvailableMethods(List pMethods, ShippingGroup pShippingGroup, RepositoryItem pPricingModel, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters) throws PricingException {
    }
    }
    3. Add the shipping calculator to Shipping Engine
    /atg/commerce/pricing/ShippingPricingEngine.properties 
    preCalculators+=/com/commerce/shipping/FixedPriceServiceCaclulator