/// <summary>
 /// Apply a ship method to this basket shipment
 /// </summary>
 /// <param name="shipMethod">The ship method to apply</param>
 public void ApplyShipMethod(ShipMethod shipMethod)
 {
     if (shipMethod == null) throw new ArgumentNullException("shipMethod");
     //WIPE OUT ANY SHIPPING CHARGES CURRENTLY IN THIS SHIPMENT
     this.ShipMethodId = shipMethod.ShipMethodId;
     this._ShipMethod = shipMethod;
     BasketItem item;
     BasketItemCollection basketItems = this.Basket.Items;
     for (int i = basketItems.Count - 1; i >= 0; i--)
     {
         item = basketItems[i];
         if (item.BasketShipmentId.Equals(this.BasketShipmentId) && ((item.OrderItemType == OrderItemType.Shipping || item.OrderItemType == OrderItemType.Handling)))
         {
             basketItems.DeleteAt(i);
         }
     }
     ShipRateQuote quote = shipMethod.GetShipRateQuote(this);
     if (quote == null) throw new ArgumentException("The specified shipping method is not valid for these items.", "shipMethod");
     item = new BasketItem();
     item.BasketId = this.BasketId;
     item.BasketShipmentId = this.BasketShipmentId;
     item.Name = quote.ShipMethod.Name;
     item.OrderItemType = OrderItemType.Shipping;
     item.Price = quote.Rate;
     item.Weight = 0;
     item.Quantity = 1;
     basketItems.Add(item);
     if (quote.Surcharge > 0)
     {
         item = new BasketItem();
         item.BasketId = this.BasketId;
         item.BasketShipmentId = this.BasketShipmentId;
         item.Name = quote.ShipMethod.Name;
         item.OrderItemType = OrderItemType.Handling;
         item.Price = quote.Surcharge;
         item.Weight = 0;
         item.Quantity = 1;
         basketItems.Add(item);
     }
     basketItems.Save();
     this.Save();
 }
        /// <summary>
        /// Gets a collection of items represented by this shipment
        /// </summary>
        /// <returns></returns>
        public BasketItemCollection GetItems()
        {
            BasketItemCollection items = new BasketItemCollection();

            if (this.Order != null)
            {
                foreach (OrderItem item in this.Order.Items)
                {
                    items.Add(item.GetBasketItem());
                }
            }
            return(items);
        }
        /// <summary>
        /// Get the child items of the given basket item.
        /// </summary>
        /// <param name="basketItem">BasketItem to get the child items for</param>
        /// <param name="orderItemTypes">Type of order item objects to include</param>
        /// <returns>A collection of child items of the given basket item</returns>
        public BasketItemCollection GetChildItems(BasketItem basketItem, params OrderItemType[] orderItemTypes)
        {
            BasketItemCollection childProducts = new BasketItemCollection();

            foreach (BasketItem item in this)
            {
                if (item.IsChildItem && item.ParentItemId == basketItem.BasketItemId &&
                    Array.IndexOf(orderItemTypes, item.OrderItemType) > -1)
                {
                    childProducts.Add(item);
                }
            }
            return(childProducts);
        }