public void Exercise_14_3_Fulfill_Order_Package()
        {
            var orderResource    = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
            var packageResource  = new Mozu.Api.Resources.Commerce.Orders.PackageResource(_apiContext);
            var shipmentResource = new Mozu.Api.Resources.Commerce.Orders.ShipmentResource(_apiContext);

            var fulfillmentInfoResource = new Mozu.Api.Resources.Commerce.Orders.FulfillmentInfoResource(_apiContext);

            var fulfillmentActionResource = new Mozu.Api.Resources.Commerce.Orders.FulfillmentActionResource(_apiContext);

            var orderNumber = 6;
            var filter      = string.Format("OrderNumber eq '{0}'", orderNumber);

            var existingOrder = (orderResource.GetOrdersAsync(startIndex: 0, pageSize: 1, filter: filter).Result).Items[0];

            var existingOrderItems = existingOrder.Items;

            var packageItems = new List <Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem>();

            foreach (var orderItem in existingOrderItems)
            {
                packageItems.Add(new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem()
                {
                    ProductCode         = String.IsNullOrWhiteSpace(orderItem.Product.VariationProductCode) ? orderItem.Product.ProductCode : orderItem.Product.VariationProductCode,
                    Quantity            = orderItem.Quantity,
                    FulfillmentItemType = "Physical"
                                          //LineId = orderItem.LineId
                });
            }

            var package = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package()
            {
                Measurements = new Mozu.Api.Contracts.CommerceRuntime.Commerce.PackageMeasurements()
                {
                    Height = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit  = "in",
                        Value = 10m
                    },
                    Length = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit  = "in",
                        Value = 10m
                    },
                    Width = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit  = "in",
                        Value = 10m
                    },
                    Weight = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit  = "lbs",
                        Value = 10m
                    },
                },
                Items         = packageItems,
                PackagingType = "CUSTOM",
            };

            var availableShippingMethods = shipmentResource.GetAvailableShipmentMethodsAsync(existingOrder.Id).Result;

            package.ShippingMethodCode      = availableShippingMethods[0].ShippingMethodCode;
            package.ShippingMethodName      = availableShippingMethods[0].ShippingMethodName;
            package.FulfillmentLocationCode = "WRH01";
            package.Code = "Package-01";
            Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package updatedPackage = null;
            try
            {
                updatedPackage = packageResource.CreatePackageAsync(package, existingOrder.Id).Result;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            var packageIds = new List <string>();

            if (updatedPackage == null)
            {
                packageIds.Add(existingOrder.Packages[0].Id);
            }
            else
            {
                packageIds.Add(updatedPackage.Id);
            }
            //var updatedPackageShipment = shipmentResource.CreatePackageShipmentsAsync(packageIds, existingOrder.Id).Result;

            var fulfilledShipment = fulfillmentActionResource.PerformFulfillmentActionAsync(
                new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.FulfillmentAction()
            {
                ActionName        = "Ship", // {Ship,Fulfill}
                DigitalPackageIds = new List <string>(),
                PackageIds        = packageIds,
                PickupIds         = new List <string>()
            },
                existingOrder.Id)
                                    .Result;
        }
        public void Exercise_14_3_Fulfill_Order_Package()
        {
            var orderResource = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
            var packageResource = new Mozu.Api.Resources.Commerce.Orders.PackageResource(_apiContext);
            var shipmentResource = new Mozu.Api.Resources.Commerce.Orders.ShipmentResource(_apiContext);

            var fulfillmentInfoResource = new Mozu.Api.Resources.Commerce.Orders.FulfillmentInfoResource(_apiContext);

            var fulfillmentActionResource = new Mozu.Api.Resources.Commerce.Orders.FulfillmentActionResource(_apiContext);

            var orderNumber = 6;
            var filter = string.Format("OrderNumber eq '{0}'", orderNumber);

            var existingOrder = (orderResource.GetOrdersAsync(startIndex: 0, pageSize: 1, filter: filter).Result).Items[0];

            var existingOrderItems = existingOrder.Items;

            var packageItems = new List<Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem>();

            foreach (var orderItem in existingOrderItems)
            {

                packageItems.Add(new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem()
                {
                    ProductCode = String.IsNullOrWhiteSpace(orderItem.Product.VariationProductCode) ? orderItem.Product.ProductCode : orderItem.Product.VariationProductCode,
                    Quantity = orderItem.Quantity,
                    FulfillmentItemType = "Physical"
                    //LineId = orderItem.LineId
                });
            }

            var package = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package()
            {
                Measurements = new Mozu.Api.Contracts.CommerceRuntime.Commerce.PackageMeasurements()
                {
                    Height = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit = "in",
                        Value = 10m
                    },
                    Length = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit = "in",
                        Value = 10m
                    },
                    Width = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit = "in",
                        Value = 10m
                    },
                    Weight = new Mozu.Api.Contracts.Core.Measurement()
                    {
                        Unit = "lbs",
                        Value = 10m
                    },
                },
                Items = packageItems,
                PackagingType = "CUSTOM",
            };

            var availableShippingMethods = shipmentResource.GetAvailableShipmentMethodsAsync(existingOrder.Id).Result;
            package.ShippingMethodCode = availableShippingMethods[0].ShippingMethodCode;
            package.ShippingMethodName = availableShippingMethods[0].ShippingMethodName;
            package.FulfillmentLocationCode = "WRH01";
            package.Code = "Package-01";
            Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package updatedPackage = null;
            try
            {
                updatedPackage = packageResource.CreatePackageAsync(package, existingOrder.Id).Result;
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            var packageIds = new List<string>();
            if(updatedPackage == null)
            {
                packageIds.Add(existingOrder.Packages[0].Id);
            }
            else
            {
                packageIds.Add(updatedPackage.Id);
            }
            //var updatedPackageShipment = shipmentResource.CreatePackageShipmentsAsync(packageIds, existingOrder.Id).Result;

            var fulfilledShipment = fulfillmentActionResource.PerformFulfillmentActionAsync(
                new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.FulfillmentAction()
                {
                    ActionName = "Ship", // {Ship,Fulfill}
                    DigitalPackageIds = new List<string>(),
                    PackageIds = packageIds,
                    PickupIds = new List<string>()
                },
                existingOrder.Id)
                .Result;
        }