Click or drag to resize

Create Incomplete Courier Order

[This is preliminary documentation and is subject to change.]

This walkthrough is for creating a courier (Purolator, Canada Post, PuroPost) order in multiple steps using AddOrder(OrderRequestV3) to create the order, and AddPackage(AddPackageRequestV3) and/or AddItem(AddItemRequestV3) to update the order information; if you are creating an LTL order then see the LTL walkthrough. This walkthrough assumes that Purolator is handling customs; if you are using a different customs broker then ignore code related to Item data.

  1. Create an order with no packages using AddOrder(OrderRequestV3).

    If Purolator is handling customs for the account, then customs information for at least one item is required, otherwise the item information is ignored.

    CredentialInfo credentials = new CredentialInfo { UserName = "User", Password = "****", ClientID = "0000000" };
    
    OrderRequestV3 orderRequest = new OrderRequestV3
    {
        Credentials = credentials,
        ShipToAddress = new Address
        {
            Name       = "Test Customer Name",
            Add1       = "560 Kings Road",
            City       = "Sydney",
            StateProv  = "NS",
            PostalCode = "B1S1B8",
            Country    = "CA"
        },
        OrderNumber    = "Order-13544364-2",
        ShipMethod     = "Purolator Ground",
        LabelType      = "ZPLIMAGES",
        ShipDate       = DateTime.Today,
        // Package data not yet available.
        Items = new List<RequestItemV3>
        {
            new RequestItemV3
            {
                SKU         = "x35135",
                CustomsDesc = "Documents",
                Quantity    = 2,
                TotalValue  = 10,
                Currency    = "CAD",
                CountryOfOrigin = "United States",
            }
        }.ToArray()
    };
  2. If the response indicated an error, fix the information and repeat step 1.

  3. When complete information for a package (a customer generated unique PackageID, weight, dimensions(optional)) is determined, use an AddPackage(AddPackageRequestV3) request to update the order and then print and attach the label to the package.

    AddPackageRequest addPackageRequest = new AddPackageRequest
    {
        Credentials = credentials,
        OrderNumber = request.OrderNumber,
        Packages = new List<RequestPackageV3>
        {
            new RequestPackageV3 { PackageID = "PKG-13544364-1", WeightUOM = "LB", Weight = 10.0m, },
            new RequestPackageV3 { PackageID = "PKG-13544364-2", WeightUOM = "LB", Weight = 2.34m, },
        }.ToArray(),
        LabelType = "ZPLIMAGES",
    };
    
    AddPackageResponse addPackageResponse = client.AddPackage(addPackageRequest);
    
    if (addPackageResponse.Status == (int)SeverityEnum.Error)
    {
        foreach (ResponseMessage message in addPackageResponse.Messages)
        {
            switch (message.Number)
            {
                case 1:  // Invalid Credentials
                    Console.Write("Invalid Credentials");
                    return addPackageResponse;
                case 80: // Duplicate Package Numbers
                    for (int index = 0; index < addPackageRequest.Packages.Length; index++)
                        addPackageRequest.Packages[index].PackageID += "-" + (index + 1);
                    break;
            }
            // Add cases to fix other errors....
        }
    
        addPackageResponse = client.AddPackage(addPackageRequest);
        if (addPackageResponse.Status == (int)SeverityEnum.Error)
            return null;
    }
  4. Print and apply the label for each package. See ZPL page for more information.

    foreach (ResponsePackage package in addPackageResponse.Packages)
    {
        // This method sends raw ZPL data to the printer using Windows API.
        RawDataPrinterHelper.SendStringToPrinter(zplPrinterName, package.ZPLCode);
    }
  5. If any additional customs item information needs to be added, AddItem(AddItemRequestV3) can be used to add item information.

    AddItemRequest addItemRequest = new AddItemRequest
    {
        Credentials = credentials,
        OrderNumber = request.OrderNumber,
        Items = new List<RequestItemV3>
        {
            new RequestItemV3
            {
                SKU         = "x35135",
                CustomsDesc = "Documents",
                Quantity    = 3,
                TotalValue  = 2.35m,
                Currency    = "CAD",
                CountryOfOrigin = "United States",
            },
        }.ToArray()
    };
    
    AddItemResponse addItemResponse = client.AddItem(addItemRequest);
    
    if (addItemResponse.Status == (int)SeverityEnum.Error)
    {
        foreach (ResponseMessage message in addItemResponse.Messages)
        {
            switch (message.Number)
            {
                case 1:  // Invalid Credentials
                    Console.Write("Invalid Credentials");
                    return;
                case 60: // SKU is required.
                    foreach (RequestItemV3 requestItem in addItemRequest.Items.Where(item => string.IsNullOrEmpty(item.SKU)))
                        if (requestItem.CustomsDesc == "Documents")
                            requestItem.SKU = "x35135";
                    break;
            }
            // Add cases to fix other errors....
        }
    
        addItemResponse = client.AddItem(addItemRequest);
        if (addItemResponse.Status == (int)SeverityEnum.Error)
            return;
    }
  6. When all orders have the correct labels attached and are ready to ship, create a Closeout to complete processing. See the Closeout page for more information.