Skip to content

Configure Shipping Providers

⏱ 20 minutes intermediate
πŸ“œCorecommerce

Shipping costs and delivery speed are top factors in purchase decisions. Customers abandon carts when shipping is too expensive or delivery estimates are unclear. Commerce lets you define multiple shipping methods, calculate rates dynamically, and integrate with carriers so customers see accurate options at checkout.

This guide covers setting up shipping methods, implementing rate calculation, and defining fulfillment rules.

  1. Create shipping methods in Commerce
  2. Implement a custom shipping gateway for rate calculation
  3. Integrate a carrier API for live rates
  4. Define fulfillment rules per warehouse

Shipping methods define the options customers see at checkout (e.g., Standard, Express, Overnight).

In the Commerce UI:

  1. Navigate to Commerce > Administration > Shipping Methods
  2. Click Add Shipping Method
  3. Select the market and language
  4. Enter a name, description, and sort order
  5. Set the shipping gateway (built-in or custom)
  6. Define the base cost and currency

For custom rate logic, implement IShippingGateway. Commerce calls your gateway to calculate the shipping cost for each shipment.

Custom shipping rate gateway
csharp
using EPiServer.Commerce.Order;
using Mediachase.Commerce;
using Mediachase.Commerce.Orders;

public class WeightBasedShippingGateway
    : IShippingGateway
{
    public ShippingRate GetRate(
        Guid methodId,
        IShipment shipment,
        ref string message)
    {
        var totalWeight = shipment.LineItems
            .Sum(item => GetItemWeight(item.Code)
                * item.Quantity);

        decimal rate;
        string methodName;

        if (totalWeight <= 1.0m)
        {
            rate = 5.99m;
            methodName = "Standard (1-5 days)";
        }
        else if (totalWeight <= 5.0m)
        {
            rate = 9.99m;
            methodName = "Standard (3-7 days)";
        }
        else
        {
            rate = 14.99m + (totalWeight - 5.0m) * 1.50m;
            methodName = "Heavy Package (5-10 days)";
        }

        return new ShippingRate(
            methodId,
            methodName,
            new Money(rate, shipment.ParentOrderGroup
                .Currency));
    }

    private decimal GetItemWeight(string code)
    {
        // Look up weight from catalog entry
        return 0.5m;
    }
}

For live rates from carriers like UPS, FedEx, or DHL, call the carrier API from your shipping gateway.

Carrier API integration pattern
csharp
public class CarrierShippingGateway
    : IShippingGateway
{
    private readonly HttpClient _httpClient;

    public CarrierShippingGateway(
        HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public ShippingRate GetRate(
        Guid methodId,
        IShipment shipment,
        ref string message)
    {
        var request = BuildRateRequest(shipment);

        try
        {
            var response = _httpClient
                .PostAsJsonAsync(
                    "https://api.carrier.com/rates",
                    request)
                .GetAwaiter().GetResult();

            var rateResponse = response.Content
                .ReadFromJsonAsync<CarrierRateResponse>()
                .GetAwaiter().GetResult();

            return new ShippingRate(
                methodId,
                rateResponse.ServiceName,
                new Money(rateResponse.TotalCost,
                    shipment.ParentOrderGroup.Currency));
        }
        catch (Exception ex)
        {
            message = "Unable to retrieve rates.";
            return null;
        }
    }

    private object BuildRateRequest(
        IShipment shipment)
    {
        var address = shipment.ShippingAddress;
        return new
        {
            DestinationZip = address.PostalCode,
            DestinationCountry = address.CountryCode,
            Weight = shipment.LineItems
                .Sum(i => i.Quantity * 0.5m),
            PackageCount = 1
        };
    }
}

Fulfillment rules determine which warehouse ships an order based on inventory availability and proximity.

RuleDescription
Closest warehouseShip from the warehouse nearest the delivery address
Inventory priorityShip from the warehouse with the highest stock
Single shipmentOnly use warehouses that can fulfill the entire order
Split shipmentAllow multiple warehouses to fulfill different line items
IssueCauseFix
No shipping options at checkoutShipping methods not configured for the active marketAdd shipping methods for the correct market in Commerce admin
Rates always return $0Gateway returning null or zeroDebug the GetRate method; verify weight and address data are populated
Carrier API timeoutNetwork or authentication issueCheck API credentials and add retry logic with a fallback flat rate
Free shipping not applyingPromotion engine not running before shipping calculationRun the promotion engine before calculating shipping rates