Class DefaultShipEngineService
- java.lang.Object
-
- com.broadleafcommerce.shipping.service.integrations.shipengine.service.DefaultShipEngineService
-
- All Implemented Interfaces:
ShipEngineService
public class DefaultShipEngineService extends Object implements ShipEngineService
Interacts with the ShipEngine API- Author:
- Cade Rea (cade-rea)
-
-
Constructor Summary
Constructors Constructor Description DefaultShipEngineService(org.springframework.web.reactive.function.client.WebClient webClient, ShipEngineProperties shipEngineProperties, WeightCalculationService weightCalculationService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BulkRateRequestbuildBulkRateRequest(@NonNull List<com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest> fulfillmentPricingRequests)Build a ShipEngineBulkRateRequestfrom a List ofFulfillmentPricingRequest.protected EstimateRequestbuildEstimateRequest(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Build a ShipEngineEstimateRequestfrom aFulfillmentPricingRequest.protected LabelDownloadRequestbuildLabelFromRateRequest()Build a ShipEngineLabelDownloadRequest.protected LabelRequestbuildLabelRequest(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, com.broadleafcommerce.order.common.domain.Address fromAddress)Build a ShipEngineLabelRequestfrom anOrderFulfillment.protected List<ShipEnginePackage>buildPackageList(@NonNull com.broadleafcommerce.shipping.domain.Weight packageWeight)Build aShipEnginePackagewith the given weight.protected RatesRequestbuildRatesRequest(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Build a ShipEngineRatesRequestfrom aFulfillmentPricingRequest.protected ShipEngineAddressbuildShipFromAddress(com.broadleafcommerce.order.common.domain.Address fromAddress)Build aShipEngineAddressfrom anAddress.protected ShipEngineAddressbuildShipFromAddress(com.broadleafcommerce.shipping.domain.ShippingAddress fromAddress)Build aShipEngineAddressfrom aShippingAddress.protected ShipEngineShipmentbuildShipment(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Build aShipEngineShipmentfrom the givenFulfillmentPricingRequest.protected ShipEngineAddressbuildShipToAddress(@NonNull com.broadleafcommerce.order.common.domain.Address toAddress)Build aShipEngineAddressfrom anAddressprotected ShipEngineAddressbuildShipToAddress(@NonNull com.broadleafcommerce.shipping.domain.ShippingAddress toAddress, String customerName)Build aShipEngineAddressfrom aShippingAddressand customer name.protected <I,O>
OcallShipEngineAPI(ShipEngineRequest<I,O> shipEngineRequest)Calls the ShipEngine API.protected StringgetAddressValidationMode()Get the configured address validation modeBulkRateResponseListgetBulkRates(@NonNull List<com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest> fulfillmentPricingRequests)Get rates for a list ofFulfillmentPricingRequest.protected List<String>getCarrierIds()Get theCarriers enabled in the ShipEngine dashboard.List<String>getCarriers()Get a list ofCarrierthat are configured in the ShipEngine account.EstimateResponsegetEstimate(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Get rate estimates from all carriers for the givenFulfillmentPricingRequest.RatesResponsegetRates(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Get all available rates for the givenFulfillmentPricingRequest.protected ShipEnginePropertiesgetShipEngineProperties()protected org.springframework.web.reactive.function.client.WebClientgetWebClient()protected WeightCalculationServicegetWeightCalculationService()protected List<String>processCarrierResponse(@NonNull ListCarriersResponse listCarriersResponse)Process aListCarriersResponsefrom ShipEngine into a list of carrier id strings.LabelResponsepurchaseLabel(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, com.broadleafcommerce.order.common.domain.Address fromAddress)Purchase a label with anOrderFulfillment.LabelResponsepurchaseLabelFromRate(@NonNull String rateId)Purchase a label from a previously quotedRate.LabelResponseretrieveLabel(@NonNull String labelId)Retrieve an existing shipping label.RateretrieveRate(@NonNull String rateId)Retrieve an existingRate.RateResponseretrieveRateForShipment(@NonNull String shipmentId)Retrieve a previously calculated rate with the shipment id.
-
-
-
Constructor Detail
-
DefaultShipEngineService
public DefaultShipEngineService(org.springframework.web.reactive.function.client.WebClient webClient, ShipEngineProperties shipEngineProperties, WeightCalculationService weightCalculationService)
-
-
Method Detail
-
getEstimate
public EstimateResponse getEstimate(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Description copied from interface:ShipEngineServiceGet rate estimates from all carriers for the givenFulfillmentPricingRequest. Estimates can be retrieved with less information than is required for a rate quote.- Specified by:
getEstimatein interfaceShipEngineService- Parameters:
fulfillmentPricingRequest- Provides addresses and items for a shipment.- Returns:
- An
EstimateResponsewith estimatedRates
-
getRates
public RatesResponse getRates(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Description copied from interface:ShipEngineServiceGet all available rates for the givenFulfillmentPricingRequest.- Specified by:
getRatesin interfaceShipEngineService- Parameters:
fulfillmentPricingRequest- Provides addresses and items for a shipment.- Returns:
- A
RatesResponsewith a list ofRates.
-
getBulkRates
public BulkRateResponseList getBulkRates(@NonNull @NonNull List<com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest> fulfillmentPricingRequests)
Description copied from interface:ShipEngineServiceGet rates for a list ofFulfillmentPricingRequest. This is an asynchronous operation on ShipEngine. Rates should be retrieved withShipEngineService.retrieveRateForShipment(java.lang.String)- Specified by:
getBulkRatesin interfaceShipEngineService- Parameters:
fulfillmentPricingRequests- Provides addresses and items for a shipment.- Returns:
- A
BulkRateResponseListwith a list of statuses for each shipment submitted. - See Also:
- ShipEngine Docs - Rate Multiple Shipments
-
retrieveRateForShipment
public RateResponse retrieveRateForShipment(@NonNull @NonNull String shipmentId)
Description copied from interface:ShipEngineServiceRetrieve a previously calculated rate with the shipment id. This can be used withShipEngineService.getBulkRates(java.util.List<com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest>)to retrieve the rates from a bulk request.- Specified by:
retrieveRateForShipmentin interfaceShipEngineService- Parameters:
shipmentId- The ShipEngine id of the shipment- Returns:
- A
RatesResponsewith a list ofRates.
-
purchaseLabel
public LabelResponse purchaseLabel(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, @Nullable com.broadleafcommerce.order.common.domain.Address fromAddress)
Description copied from interface:ShipEngineServicePurchase a label with anOrderFulfillment. TheFulfillmentOptionshould be set on theOrderFulfillment.- Specified by:
purchaseLabelin interfaceShipEngineService- Parameters:
orderFulfillment- Provides addresses and items for a shipment.fromAddress- The address that the package will be sent from. If not provided, will use the default address configured with properties. SeeShipEngineProperties.DefaultFromAddress.- Returns:
- A
LabelResponsewith a URL to download the shipping label.
-
purchaseLabelFromRate
public LabelResponse purchaseLabelFromRate(@NonNull @NonNull String rateId)
Description copied from interface:ShipEngineServicePurchase a label from a previously quotedRate.- Specified by:
purchaseLabelFromRatein interfaceShipEngineService- Parameters:
rateId- The ShipEngine rate id.- Returns:
- A
LabelResponsewith a URL to download the shipping label.
-
getCarriers
public List<String> getCarriers()
Description copied from interface:ShipEngineServiceGet a list ofCarrierthat are configured in the ShipEngine account.- Specified by:
getCarriersin interfaceShipEngineService- Returns:
- A list of Carriers that are configured in the ShipEngine dashboard.
-
retrieveRate
public Rate retrieveRate(@NonNull @NonNull String rateId)
Description copied from interface:ShipEngineServiceRetrieve an existingRate.- Specified by:
retrieveRatein interfaceShipEngineService- Parameters:
rateId- The ShipEngine rate id.- Returns:
- The
Rateassociated with the given rateId.
-
retrieveLabel
public LabelResponse retrieveLabel(@NonNull @NonNull String labelId)
Description copied from interface:ShipEngineServiceRetrieve an existing shipping label. This method does not purchase labels.- Specified by:
retrieveLabelin interfaceShipEngineService- Parameters:
labelId- The ShipEngine label id.- Returns:
- A
LabelResponsewith a URL to download the shipping label.
-
buildEstimateRequest
protected EstimateRequest buildEstimateRequest(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Build a ShipEngineEstimateRequestfrom aFulfillmentPricingRequest.- Parameters:
fulfillmentPricingRequest- Provides addresses and items for a shipment.- Returns:
- An
EstimateRequestto send to ShipEngine.
-
buildRatesRequest
protected RatesRequest buildRatesRequest(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Build a ShipEngineRatesRequestfrom aFulfillmentPricingRequest.- Parameters:
fulfillmentPricingRequest- Provides addresses and items for a shipment.- Returns:
- A
RatesRequestto send to ShipEngine.
-
buildBulkRateRequest
protected BulkRateRequest buildBulkRateRequest(@NonNull @NonNull List<com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest> fulfillmentPricingRequests)
Build a ShipEngineBulkRateRequestfrom a List ofFulfillmentPricingRequest.- Parameters:
fulfillmentPricingRequests- Provides addresses and items for shipments.- Returns:
- A
BulkRateRequestto send to ShipEngine.
-
buildLabelRequest
protected LabelRequest buildLabelRequest(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, @Nullable com.broadleafcommerce.order.common.domain.Address fromAddress)
Build a ShipEngineLabelRequestfrom anOrderFulfillment.- Parameters:
orderFulfillment- Provides addresses and items for a shipment.fromAddress- The address that the package will be sent from. If not provided, will use the default address configured with properties. SeeShipEngineProperties.DefaultFromAddress.- Returns:
- A
LabelRequestto send to ShipEngine.
-
buildLabelFromRateRequest
protected LabelDownloadRequest buildLabelFromRateRequest()
Build a ShipEngineLabelDownloadRequest.- Returns:
- A
LabelDownloadRequestto send to ShipEngine.
-
processCarrierResponse
protected List<String> processCarrierResponse(@NonNull @NonNull ListCarriersResponse listCarriersResponse)
Process aListCarriersResponsefrom ShipEngine into a list of carrier id strings.- Parameters:
listCarriersResponse- TheListCarriersResponsefrom ShipEngine.- Returns:
- A list of
Carrierids.
-
callShipEngineAPI
protected <I,O> O callShipEngineAPI(ShipEngineRequest<I,O> shipEngineRequest)
Calls the ShipEngine API. The givenShipEngineRequestshould have all data needed for the API call.- Type Parameters:
I- The type of Input, ie the type of the body of the request.O- The type of Output, ie the response type- Parameters:
shipEngineRequest- Holds request header and body data needed by WebClient to exchange with the ShipEngine API.- Returns:
- An object of type O
-
getCarrierIds
protected List<String> getCarrierIds()
Get theCarriers enabled in the ShipEngine dashboard. This will make an API call unlessShipEngineProperties.getCarriersFromPropertiesis true. In that case, carrier ids can be specified inShipEngineProperties.carriers.- Returns:
- A list of
Carrierid strings.
-
buildShipment
protected ShipEngineShipment buildShipment(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Build aShipEngineShipmentfrom the givenFulfillmentPricingRequest.- Parameters:
fulfillmentPricingRequest- Provides addresses and items for a shipment.- Returns:
- A
ShipEngineShipmentto be included in a ShipEngine request.
-
buildPackageList
protected List<ShipEnginePackage> buildPackageList(@NonNull @NonNull com.broadleafcommerce.shipping.domain.Weight packageWeight)
Build aShipEnginePackagewith the given weight.- Parameters:
packageWeight- TheWeightof the package.- Returns:
- A singleton list of
ShipEnginePackageto include in other requests.
-
getAddressValidationMode
protected String getAddressValidationMode()
Get the configured address validation mode- Returns:
- The address validation mode
-
buildShipToAddress
protected ShipEngineAddress buildShipToAddress(@NonNull @NonNull com.broadleafcommerce.shipping.domain.ShippingAddress toAddress, String customerName)
Build aShipEngineAddressfrom aShippingAddressand customer name.- Parameters:
toAddress- The destination address for the package.customerName- The name of the recipient.- Returns:
- A
ShipEngineAddressto include in a ShipEngine request.
-
buildShipToAddress
protected ShipEngineAddress buildShipToAddress(@NonNull @NonNull com.broadleafcommerce.order.common.domain.Address toAddress)
Build aShipEngineAddressfrom anAddress- Parameters:
toAddress- The destination address for the package.- Returns:
- A
ShipEngineAddressto include in a ShipEngine request.
-
buildShipFromAddress
protected ShipEngineAddress buildShipFromAddress(@Nullable com.broadleafcommerce.shipping.domain.ShippingAddress fromAddress)
Build aShipEngineAddressfrom aShippingAddress. If the provided address is null, this will use the default FROM address configured withShipEngineProperties.DefaultFromAddress.- Parameters:
fromAddress- The address that the package is being shipped from.- Returns:
- A
ShipEngineAddressto include in a ShipEngine request.
-
buildShipFromAddress
protected ShipEngineAddress buildShipFromAddress(@Nullable com.broadleafcommerce.order.common.domain.Address fromAddress)
Build aShipEngineAddressfrom anAddress. If the provided address is null, this will use the default FROM address configured withShipEngineProperties.DefaultFromAddress.- Parameters:
fromAddress- The address that the package is being shipped from.- Returns:
- A
ShipEngineAddressto include in a ShipEngine request.
-
getWebClient
protected org.springframework.web.reactive.function.client.WebClient getWebClient()
-
getShipEngineProperties
protected ShipEngineProperties getShipEngineProperties()
-
getWeightCalculationService
protected WeightCalculationService getWeightCalculationService()
-
-