Configure Shipping Providers
Why shipping configuration matters
Section titled βWhy shipping configuration mattersβ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.
What you will do
Section titled βWhat you will doβ- Create shipping methods in Commerce
- Implement a custom shipping gateway for rate calculation
- Integrate a carrier API for live rates
- Define fulfillment rules per warehouse
Create shipping methods
Section titled βCreate shipping methodsβShipping methods define the options customers see at checkout (e.g., Standard, Express, Overnight).
In the Commerce UI:
- Navigate to Commerce > Administration > Shipping Methods
- Click Add Shipping Method
- Select the market and language
- Enter a name, description, and sort order
- Set the shipping gateway (built-in or custom)
- Define the base cost and currency
Implement a shipping rate gateway
Section titled βImplement a shipping rate gatewayβFor custom rate logic, implement IShippingGateway. Commerce calls your gateway to calculate the shipping cost for each shipment.
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;
}
} Integrate a carrier API
Section titled βIntegrate a carrier APIβFor live rates from carriers like UPS, FedEx, or DHL, call the carrier API from your shipping gateway.
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
};
}
} Define fulfillment rules
Section titled βDefine fulfillment rulesβFulfillment rules determine which warehouse ships an order based on inventory availability and proximity.
| Rule | Description |
|---|---|
| Closest warehouse | Ship from the warehouse nearest the delivery address |
| Inventory priority | Ship from the warehouse with the highest stock |
| Single shipment | Only use warehouses that can fulfill the entire order |
| Split shipment | Allow multiple warehouses to fulfill different line items |
Common issues
Section titled βCommon issuesβ| Issue | Cause | Fix |
|---|---|---|
| No shipping options at checkout | Shipping methods not configured for the active market | Add shipping methods for the correct market in Commerce admin |
| Rates always return $0 | Gateway returning null or zero | Debug the GetRate method; verify weight and address data are populated |
| Carrier API timeout | Network or authentication issue | Check API credentials and add retry logic with a fallback flat rate |
| Free shipping not applying | Promotion engine not running before shipping calculation | Run the promotion engine before calculating shipping rates |