Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Shipping Calculator Implementation

Shipping Calculator Implementation

You can implement a shipping calculation plug-in by creating a class that extends AbstractShippingCalculationPlugin and implements the following ShippingCalculationCapability interfaces:
  • ShippingCostCalculationCapability
  • ShippingOptionListCapability
  • ShippingOptionListAllCapability
  • ShippingOptionListPerDestinationCapability
Capability Methods Defined
ShippingCostCalculationCapability None, a marker interface to designate which capability interfaces are shipping calculation ones.
ShippingOptionListCapability getUnpricedShippingOptions(ShippableItemContainer<?> unpricedShippableItemContainer);

Returns a List<ShippingOption> object that lists all shipping options for an unpriced lookup.

ShippingOptionListAllCapability getAllShippingOptions(String storeCode, Locale locale);

Returns a List<ShippingOption> object that lists all shipping options for the specific store.

ShippingOptionListPerDestinationCapability
getUnpricedShippingOptions(ShippingAddress destinationAddress,
String storeCode, 
Locale locale);

Returns a List<ShippingOption> object that lists all shipping options for the given store and destination address.

Caching Implementation

Caching is implemented in the com.elasticpath.shipping.connectivity.service.cache package. The caching service consists of the following:
  • The CachingShippingCalculationServiceImpl class, which implements ShippingCalculationService. The ShippingCalculationService implementation provides cached shipping options to the user through the ShippingOptionService.
  • The ShippingCalculationResultCacheKey interface and a default implementation of this interface, ShippingCalculationResultCacheKeyImpl. This implementation defines information as a key to retrieve the cached shipping option.
  • The ShippingCalculationResultCacheKeyBuilder interface and default implementation of this interface, ShippingCalculationResultCacheKeyBuilder. Use this class to create cache keys for shipping options.

Selection of a Shipping Calculation Plugin

The selection of a shipping calculation plugin is defined in the PricedShippingCalculationPluginSelector and UnpricedShippingCalculationPluginSelector interfaces in the com.elasticpath.shipping.connectivity.service.selector package. The default implementation of these interfaces returns the default Elastic Path shipping calculator plugin.

A selector might choose different plugins based on the Elastic Path store being serviced for store-specific shipping plugins. A selector can also choose a different plugin depending on what is being shipped. For example, if you want high value goods to be shipped by a particular shipping provider, such as FedEx rather than USPS, you can implement that functionality in the selector class.

When implementing a new shipping calculation plugin, you must override the default implementation of the following methods to return the shipping calculator plugin implementation:
  • PricedShippingCalculationPluginSelector.getPricedShippingCalculationPlugin()
  • UnpricedShippingCalculationPluginSelector.getUnpricedShippingCalculationPlugin()

These implementations must provide logic to select your shipping calculation plugin, however the default setting must be to select Elastic Path's default shipping calculator plugin.