1
2
3
4
5
6
7
8
9
10
11
12
13
14 package nl.tudelft.simulation.supplychain.handlers;
15
16 import java.io.Serializable;
17 import java.util.Comparator;
18 import java.util.List;
19
20 import nl.tudelft.simulation.jstats.distributions.DistContinuous;
21 import nl.tudelft.simulation.supplychain.actor.SupplyChainActor;
22 import nl.tudelft.simulation.supplychain.content.ContentStore;
23 import nl.tudelft.simulation.supplychain.content.Order;
24 import nl.tudelft.simulation.supplychain.content.OrderBasedOnQuote;
25 import nl.tudelft.simulation.supplychain.content.Quote;
26 import nl.tudelft.simulation.supplychain.content.RequestForQuote;
27
28 /***
29 * The QuoteHandlerAll just waits patiently till all the Quotes are in for each
30 * RequestForQuote that has been sent out. When that happens, it chooses the
31 * best offer, based on price and distance. <br>
32 * <br>
33 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
34 * Delft, the Netherlands. All rights reserved.
35 *
36 * See for project information <a href="http://www.simulation.tudelft.nl/">
37 * www.simulation.tudelft.nl </a>.
38 *
39 * The source code and binary code of this software is proprietary information
40 * of Delft University of Technology.
41 *
42 * @author <a
43 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
44 * Verbraeck </a>
45 * @version $$Revision: 1.3 $$ $$Date: 2005/04/08 12:00:56 $$
46 */
47 public class QuoteHandlerAll extends QuoteHandler
48 {
49 /*** the serial version uid */
50 private static final long serialVersionUID = 12L;
51
52 /***
53 * Constructor of the QuoteHandlerAll with a user defined comparator for
54 * quotes
55 *
56 * @param owner the actor for this QuoteHandler.
57 * @param comparator the predefined sorting comparator type.
58 * @param handlingTime the time to handle the quotes
59 * @param maximumPriceMargin the maximum margin (e.g. 0.4 for 40 % above
60 * unitprice) above the unitprice of a product
61 */
62 public QuoteHandlerAll(final SupplyChainActor owner,
63 final Comparator comparator, final DistContinuous handlingTime,
64 final double maximumPriceMargin)
65 {
66 super(owner, comparator, handlingTime, maximumPriceMargin);
67 }
68
69 /***
70 * Constructor of the QuoteHandlerAll with a user defined comparators for
71 * quotes
72 *
73 * @param owner the actor for this QuoteHandler.
74 * @param comparator the predefined sorting comparator type.
75 * @param handlingTime the time to handle the quotes
76 * @param maximumPriceMargin the maximum margin (e.g. 0.4 for 40 % above
77 * unitprice) above the unitprice of a product
78 */
79 public QuoteHandlerAll(final SupplyChainActor owner,
80 final Comparator comparator, final double handlingTime,
81 final double maximumPriceMargin)
82 {
83 super(owner, comparator, handlingTime, maximumPriceMargin);
84 }
85
86 /***
87 * Constructor of the QuoteHandlerAll with a one of the predefined
88 * comparators for quotes
89 *
90 * @param owner the actor for this QuoteHandler.
91 * @param comparatorType the predefined sorting comparator type.
92 * @param handlingTime the time to handle the quotes
93 * @param maximumPriceMargin the maximum margin (e.g. 0.4 for 40 % above
94 * unitprice) above the unitprice of a product
95 */
96 public QuoteHandlerAll(final SupplyChainActor owner,
97 final int comparatorType, final DistContinuous handlingTime,
98 final double maximumPriceMargin)
99 {
100 super(owner, comparatorType, handlingTime, maximumPriceMargin);
101 }
102
103 /***
104 * Constructor of the QuoteHandlerAll with a one of the predefined
105 * comparators for quotes
106 *
107 * @param owner the actor for this QuoteHandler.
108 * @param comparatorType the predefined sorting comparator type.
109 * @param handlingTime the time to handle the quotes
110 * @param maximumPriceMargin the maximum margin (e.g. 0.4 for 40 % above
111 * unitprice) above the unitprice of a product
112 */
113 public QuoteHandlerAll(final SupplyChainActor owner,
114 final int comparatorType, final double handlingTime,
115 final double maximumPriceMargin)
116 {
117 super(owner, comparatorType, handlingTime, maximumPriceMargin);
118 }
119
120 /***
121 * @see nl.tudelft.simulation.content.HandlerInterface#handleContent(java.io.Serializable)
122 */
123 public boolean handleContent(final Serializable content)
124 {
125 Quote quote = (Quote) checkContent(content);
126 if (!isValidContent(quote))
127 {
128 return false;
129 }
130
131 Serializable id = quote.getInternalDemandID();
132 ContentStore contentStore = super.owner.getContentStore();
133 if (contentStore.getContentList(id, Quote.class).size() == contentStore
134 .getContentList(id, RequestForQuote.class).size())
135 {
136
137 List quotes = contentStore.getContentList(id, Quote.class);
138 Quote bestQuote = selectBestQuote(quotes);
139 Order order = new OrderBasedOnQuote(super.owner, bestQuote
140 .getSender(), id, bestQuote.getProposedDeliveryDate(),
141 bestQuote);
142 super.owner.sendContent(order, this.handlingTime.draw());
143 }
144 return true;
145 }
146 }