KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > shipping > PriceBasedShippingMethod


1 /*
2  * Created on May 26, 2004
3  */

4 package com.openedit.store.shipping;
5
6 import java.util.Iterator JavaDoc;
7
8 import org.openedit.money.Money;
9
10 import com.openedit.store.Cart;
11 import com.openedit.store.CartItem;
12
13
14 /**
15  * @author cburkey
16  *
17  */

18 public class PriceBasedShippingMethod extends BaseShippingMethod
19 {
20     public Money getCost(Cart inCart)
21     {
22         Money totalPrice = getHandlingCharge(inCart);
23         totalPrice = totalPrice.add(getCost());
24
25         return totalPrice;
26     }
27     public boolean applies(Cart inCart)
28     {
29         double subTotal = inCart.getSubTotal().doubleValue();
30         
31         //If any products have a fixed shipping method
32
//Then we must include that in the list
33
//and remove it from the pricing totals remaining
34

35         for (Iterator JavaDoc iter = inCart.getItemIterator(); iter.hasNext();)
36         {
37             CartItem cartI = (CartItem) iter.next();
38             String JavaDoc method = cartI.getProduct().getShippingMethodId();
39             if ( method != null )
40             {
41                 //this has its own method and should be removed from the list
42
subTotal = subTotal - cartI.getYourPrice().doubleValue();
43             }
44         }
45
46         if ( getLowerThreshold() == null ||
47             Money.ZERO.equals(getLowerThreshold()) ||
48             getLowerThreshold().doubleValue() <= subTotal)
49         {
50             if (getUpperThreshold() == null ||
51                 getUpperThreshold().doubleValue() >= subTotal)
52             {
53
54                 return true;
55             }
56         }
57         return false;
58     }
59
60 }
61
Popular Tags