Services represent different methods of shipping from a provider. Usually the prices of these rates are based on the weight of the package, the distance the package must travel and the speed of delivery. For example, FedEx provides services such as “First Overnight”, “2 Day” and “International Priority”.
If your custom shipping provider is retrieving the services for the shipping carrier via an external service, you may want to setup the provider’s services in the backend, and then display only the active/defined services to your customer in the front end. For example, your external shipping carrier may provide 20 different service rates, but you may only want to display 4 or 5 of those rates to your customer. In this case you will define these 4 or 5 services in the backend and then use them to filter the services, returned by the provider.
To setup services for your shipping carrier provider, perform the following:
To query the predefined services for your provider, you must perform the following:
The list of shipping services will come in handy when processing the data that is returned from an external shipping carrier and that contains the shipping services and their rates. When parsing the service data that is returned from the shipping carrier, retrieve its service code and check if there is a service with the same code in your list of shipping services. If it does, then parse the rate of the service and wrap it in a GenericShippingResponse object. Use the values of the Title and SortOrder properties of the ShippingServiceSettings instance for the ServiceName and SrotOrder properties of the GenericServerResponse instance. If a service with the same code is not present, then do not add this service to your ShippingResponse list. Using this method, you can filter the set of external provider’s services down to a subset of just those services you want to provide to your customers.
Here is a code example of parsing a sample XML response of a shipping carrier’s external service:
ShippingManager shippingManager = ShippingManager.GetManager();
ShippingResponseContext shippingResponseContext =
XmlDocument doc =
XmlNodeList serviceNodes = doc.SelectNodes(
// Get a list of active services whose carrier name matches the name of the custom one.
List<ShippingServiceSettings> services = shippingManager.GetShippingServiceSettings().Where(
x => x.ShippingCarrierName == CustomShippingCarrierProvider.Name &&
// Get the code of the service.
code = serviceNode.Attributes[
// Check whether the list of predefined services contains a service with the current code.
ShippingServiceSettings service = services.Where(x => x.Code == code).SingleOrDefault();
// Check whether the service is not already added to the ShippingResponseContext.
IShippingResponse shippingResponse = shippingResponseContext.ShippingResponses.Where(x => x.ServiceCode == code).SingleOrDefault();
// Create a GenericShippingResponse object and populate it with the service name, code, and rate.
shippingResponse.ServiceCode = code;
shippingResponse.ServiceName = service.Title;
shippingResponse.ShippingCarrierName = CustomShippingCarrierProvider.Name;
shippingResponse.ShippingServiceName = serviceNode.SelectSingleNode(
shippingResponse.SortOrder = service.SortOrder;
totalCharges = serviceNode.SelectSingleNode(
shippingResponse.ServicePrice = Convert.ToDecimal(totalCharges);
// Add this response to our list of service responses
shippingResponse.ServicePrice += Convert.ToDecimal(totalCharges);
Back To Top