Class ShipEngineFulfillmentPricingProvider

    • Method Detail

      • canProvidePricedFulfillmentOptions

        public boolean canProvidePricedFulfillmentOptions​(@NonNull
                                                          @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Description copied from interface: FulfillmentPricingProvider
        Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"
        Specified by:
        canProvidePricedFulfillmentOptions in interface FulfillmentPricingProvider
        Parameters:
        fulfillmentPricingRequest - The request used to identify relevant fulfillment options
        Returns:
        Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"
      • providePricedFulfillmentOptions

        public List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse> providePricedFulfillmentOptions​(@NonNull
                                                                                                                           @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Description copied from interface: FulfillmentPricingProvider
        Retrieve all possible priced fulfillment options for the provided request. Intended to be used to display options to the customer for selection.
        Specified by:
        providePricedFulfillmentOptions in interface FulfillmentPricingProvider
        Parameters:
        fulfillmentPricingRequest - The request for which to calculate shipping and return options.
        Returns:
        All possible priced fulfillment options for the provided request.
      • calculateCostForFulfillmentGroup

        public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroup​(@NonNull
                                                                                                                      @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Description copied from interface: FulfillmentPricingProvider
        Calculate shipping for a request that includes a specified fulfillment option.
        Specified by:
        calculateCostForFulfillmentGroup in interface FulfillmentPricingProvider
        Parameters:
        fulfillmentPricingRequest - The request for which to calculate shipping.
        Returns:
        Response object with calculated shipping cost for the provided request.
      • canCalculateCostForOption

        public boolean canCalculateCostForOption​(String fulfillmentOptionName)
        Description copied from interface: FulfillmentPricingProvider
        Whether this provider has knowledge of the provided option and thus can provide cost information for it.
        Specified by:
        canCalculateCostForOption in interface FulfillmentPricingProvider
        Parameters:
        fulfillmentOptionName - The option to consider whether this provider can calculate cost information.
        Returns:
        Whether this provider has knowledge of the provided option and thus can provide cost information for it.
      • estimateCostForFulfillmentGroup

        public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse estimateCostForFulfillmentGroup​(@NonNull
                                                                                                                     @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Description copied from interface: FulfillmentPricingProvider
        Estimate shipping for a request that includes a specified fulfillment option.
        Specified by:
        estimateCostForFulfillmentGroup in interface FulfillmentPricingProvider
        Parameters:
        fulfillmentPricingRequest - The request for which to estimate shipping.
        Returns:
        Response object with estimated shipping cost for the provided request.
      • canProvideShippingLabel

        public boolean canProvideShippingLabel​(@Nullable
                                               String fulfillmentOptionName)
        Description copied from interface: ShippingLabelProvider
        Indicate if this fulfillment provider can provide shipping labels for the given fulfillment option.
        Specified by:
        canProvideShippingLabel in interface ShippingLabelProvider
        Parameters:
        fulfillmentOptionName - The name of the fulfillment option to check.
        Returns:
        true if this ShippingLabelProvider can provide a shipping label for the given fulfillmentOptionName.
      • shippingLabelIsPurchased

        public boolean shippingLabelIsPurchased​(@NonNull
                                                @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment,
                                                @Nullable
                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: ShippingLabelProvider
        Indicate if a shipping label has already been purchased for this fulfillment.
        Specified by:
        shippingLabelIsPurchased in interface ShippingLabelProvider
        Returns:
        true if there is an existing label for this fulfillment
      • provideShippingLabel

        public ShippingLabelDownload provideShippingLabel​(@NonNull
                                                          @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment,
                                                          boolean purchase,
                                                          @Nullable
                                                          com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
                                                   throws LabelException
        Description copied from interface: ShippingLabelProvider
        Get the shipping label associated with this fulfillment. If a label does not already exist, the purchase parameter will be checked to determine if a new label should be purchased.
        Specified by:
        provideShippingLabel in interface ShippingLabelProvider
        Parameters:
        orderFulfillment - The fulfillment for which to get a shipping label.
        purchase - True if shipping should be purchased, false if an existing label should be read.
        Returns:
        a Map with the label response for the shipping label
        Throws:
        LabelException
      • saveShipmentDetails

        protected ShipmentDetails saveShipmentDetails​(@NonNull
                                                      @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment,
                                                      @NonNull
                                                      @NonNull LabelResponse labelResponse,
                                                      @Nullable
                                                      com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Create and save ShipmentDetails.
        Parameters:
        orderFulfillment - Provides addresses and items for a shipment.
        labelResponse - Contains the shipping label download URL.
        contextInfo - The context of the request.
        Returns:
        A persisted ShipmentDetails.
      • buildItemPriceInfoMap

        protected Map<String,​com.broadleafcommerce.shipping.domain.FulfillmentPriceInfo> buildItemPriceInfoMap​(@NonNull
                                                                                                                     @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Build Map of item-level FulfillmentPriceInfo from each item in the given FulfillmentPricingRequest. This method sets all item-level fulfillment charges to 0.
        Parameters:
        fulfillmentPricingRequest - Provides addresses and items for a shipment.
        Returns:
        Map of FulfillmentPriceInfo for each item in the given FulfillmentPricingRequest
      • buildRatesResponse

        protected List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse> buildRatesResponse​(@NonNull
                                                                                                                 @NonNull RatesResponse ratesResponse,
                                                                                                                 @NonNull
                                                                                                                 @NonNull javax.money.CurrencyUnit currency)
        Convert a RatesResponse to a list of FulfillmentOptionPricedResponse.
        Parameters:
        ratesResponse - The response from ShipEngine.
        currency - The currency for the prices.
        Returns:
      • convertRateToPricedResponse

        protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse convertRateToPricedResponse​(@NonNull
                                                                                                                    @NonNull Rate rate,
                                                                                                                    @NonNull
                                                                                                                    @NonNull javax.money.CurrencyUnit currency)
        Convert a Rate to a FulfillmentOptionPricedResponse.
        Parameters:
        rate - The rate to convert to the FulfillmentOptionPricedResponse.
        currency - The currency for the prices.
        Returns:
        A FulfillmentOptionPricedResponse created from the given Rate.
      • formatFulfillmentOptionName

        protected String formatFulfillmentOptionName​(@NonNull
                                                     @NonNull Rate rate)
        Builds the name for a FulfillmentOptionPricedResponse from a Rate. For example, with a rate id of "se-1234", this would return "SHIPENGINE_se-1234".
        Parameters:
        rate - The rate used for building the FulfillmentOptionPricedResponse.
        Returns:
        A name for the FulfillmentOptionPricedResponse.
      • isShipEngineFulfillmentOption

        protected boolean isShipEngineFulfillmentOption​(@Nullable
                                                        String fulfillmentOptionName)
        Determine if the given String represents a FulfillmentOption created by this provider.
        Parameters:
        fulfillmentOptionName - The name of the FulfillmentOption to check.
        Returns:
        True if the given String starts with the SHIPENGINE_FUL_OPT_PREFIX.
      • formatFulfillmentOptionDescription

        protected String formatFulfillmentOptionDescription​(@NonNull
                                                            @NonNull Rate rate)
        Build the description that users will see for this FulfillmentOption.
        Parameters:
        rate - The rate used for building the FulfillmentOptionPricedResponse.
        Returns:
        A user-friendly description of the FulfillmentOption.
      • getFulfillmentRate

        protected javax.money.MonetaryAmount getFulfillmentRate​(@NonNull
                                                                @NonNull Rate rate,
                                                                @NonNull
                                                                @NonNull javax.money.CurrencyUnit currency)
        Sum the shipping, insurance, confirmation, and other amounts from the given Rate.
        Parameters:
        rate - The rate used for building the FulfillmentOptionPricedResponse.
        currency - The currency of the prices.
        Returns:
        The total of all shipping charges from the given Rate.
      • getEstimatedDeliveryDate

        @Nullable
        protected Instant getEstimatedDeliveryDate​(@NonNull
                                                   @NonNull Rate rate)
        Parse an Instant from the estimated delivery date of a Rate.
        Parameters:
        rate - The rate used for building the FulfillmentOptionPricedResponse.
        Returns:
        The Instant representation of the estimated delivery date or null if not available.
      • getTaxable

        protected boolean getTaxable()
        Taxable setting for new FulfillmentOptionPricedResponse
        Returns:
        True if new FulfillmentOptionPricedResponse should be marked as taxable.
        See Also:
        ShipEngineProperties.isTaxable()
      • addIfExists

        protected BigDecimal addIfExists​(@Nullable
                                         ShipEngineCurrencyAmount addAmount,
                                         @NonNull
                                         @NonNull BigDecimal total)
        Add the addAmount to the total if addAmount is not null
        Parameters:
        addAmount - The amount to add to the total.
        total - The running total.
        Returns:
        The same total object that is passed in.
      • setCurrencyIfNull

        protected void setCurrencyIfNull​(@NonNull
                                         @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Set the CurrencyUnit on the FulfillmentPricingRequest to the system default if it is null.
        Parameters:
        fulfillmentPricingRequest - The fulfillment being shipped.
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()