Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Setup Multiple Shipping Methods for Multiple Countries

In some cases, you do not want your delivery drones to fly across the Atlantic ocean to deliver your hardware to the customer. Luckily Ucommerce offers great capabilities to prevent those scenarios. In this article, we will cover how exactly that works and how easy it is to limit available shipping methods for your customers based on either their billing address, delivery address or something completely different.

If you're interested

Setting Up Your Shipping Methods

Shipping methods can be created directly in the backend. If you're in how shipping methods works I recommend that you take a look at How to configure a shipping method.

Custom prices for shipping methods

The single price that can be configured in the pricing tabs on your shipping method is sometimes enough for calculating the shipping costs. However if the costs are more dynamically based on some other criteria, custom calculations may be required. In that case, please refer to How to create a custom shipping method service.

Dividing shipping methods into different stores and countries

Under the access tab on each shipping method, you have the ability to divide its access per store and country.

image

Front-end API

On the front-end, it's really easy to figure out what shipping methods are available for the customer. The only thing you need to do is the following:

    
    Ucommerce.Api.ITransactionLibrary transactionLibrary = ObjectFactory.Instance.Resolve<Ucommerce.Api.ITransactionLibrary>();
    
    var country = transactionLibrary.GetShippingInformation().Country;
    //var country = transactionLibrary.GetBillingInformation().Country; or use billing address if you rather want to.
    
    ICollection<Ucommerce.EntitiesV2.ShippingMethod> shippingMethods = transactionLibrary.GetShippingMethods(country);
    
    

The country passed into GetShippingMethods can be any Country coming from where-ever. The available shipping methods are per design not tied to either Shipping or Billing country. If you prefer you can even use GEO-location as the base for what country is needed.

Once you pass in the country, Ucommerce will automatically figure out the store your customer is visiting and use that as the base for what shipping methods should be returned. Thus the shipping methods will be filtered on store first and secondly per country.

Once shipping methods have been returned you just need to create it using the following:

    int selectedShippingMethodIdFromVisitor = GetSelectedShippingMethodIdFromVisitor();
    transactionLibrary.CreateShipment(selectedShippingMethodIdFromVisitor, addressName: Ucommerce.Constants.DefaultShipmentAddressName, overwriteExisting: true);
    
    

Of course, you are free to let the customer choose, but if there is for some reason only a single option you can easily just skip the step.

Once the shipment is being created the calculation of the shipping costs will be calculated by the service attached to the shipping method.