HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Multi-shipment examples

This topic describes how to work with multi-shipment, also known as split shipment, which supports shipment to multiple address.

A split shipment could be a customer who buys two items, and each is shipped to a different address. During checkout, a customer can create a new address, or select from existing addresses.

How it works

If a customer purchases two or more items, the Ship to multiple addresses button appears during checkout.

12211221

During checkout, the information for each split shipping part is added. The number of split shipments is equal to the number of items in the cart, so the customer can add/select a shipping address for each item.

11391139

Upon completing the information for each split shipment, the order process moves to next step. Here, choosing a shipping delivery option, billing address, and payment is required.

10031003

Code examples

Example: Creating multiple shipment for Cart base on cart's LineItem

var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
    var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
    var cart = orderRepository.LoadCart(CustomerContext.Current.CurrentContactId, DefaultCartName, currentMarket);
    var form = cart.GetFirstForm();
    var cartLineItems = cart.GetAllLineItems().ToList();
    
    // Clean up line item in shipment
    foreach (var shipment in form.Shipments)
      {
        shipment.LineItems.Clear();
      }
    // Clean up shipments
    form.Shipments.Clear();
    
    // Adding shipment for each cart line item
    foreach (var item in cartLineItems)
      {
        var shipment = cart.CreateShipment(_orderGroupFactory);
        var lineItem = cart.CreateLineItem(item.Code, _orderGroupFactory);
        lineItem.IsGift = item.IsGift;
        lineItem.Quantity = item.Quantity;
        shipment.LineItems.Add(lineItem);
        form.Shipments.Add(shipment);
      }
    
    orderRepository.Save(cart);

Did this page help you?