Skip to content

Commit 320da9c

Browse files
author
reejoseph
committed
Flight SDK Example for Listing
1 parent dbf66e4 commit 320da9c

File tree

2 files changed

+314
-2
lines changed

2 files changed

+314
-2
lines changed

examples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<groupId>com.expediagroup</groupId>
2424
<artifactId>xap-java-sdk-examples</artifactId>
25-
<version>1.0-SNAPSHOT</version>
25+
<version>1.2.3-SNAPSHOT</version>
2626
<name>XAP Java SDK Examples</name>
2727
<description>Expedia Group XAP Java SDK Examples</description>
2828

@@ -31,7 +31,7 @@
3131
<maven.compiler.source>1.8</maven.compiler.source>
3232
<maven.compiler.target>1.8</maven.compiler.target>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34-
<xap-java-sdk.sdk.version>1.1.0</xap-java-sdk.sdk.version>
34+
<xap-java-sdk.sdk.version>1.2.3-SNAPSHOT</xap-java-sdk.sdk.version>
3535
</properties>
3636

3737
<repositories>
Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
package com.expediagroup.sdk.xap.examples.scenarios.flight;
2+
3+
import com.expediagroup.sdk.xap.client.XapClient;
4+
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
5+
import com.expediagroup.sdk.xap.models.FlightSearchResponse;
6+
import com.expediagroup.sdk.xap.operations.GetFlightListingsOperation;
7+
import com.expediagroup.sdk.xap.operations.GetFlightListingsOperationParams;
8+
import java.time.LocalDate;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
/**
13+
* This example demonstrates how to search for flight listings for a one-way trip with adults,
14+
* seniors, and children.
15+
*/
16+
public class FlightListingExampleTesting implements XapScenario {
17+
18+
private static final Logger LOGGER =
19+
LoggerFactory.getLogger(FlightListingExampleTesting.class);
20+
21+
22+
public static void main(String[] args) {
23+
new FlightListingExampleTesting().run();
24+
System.exit(0);
25+
}
26+
27+
@Override
28+
public void run() {
29+
LOGGER.info(
30+
"========= Running FlightListingsQuickStartScenario =============");
31+
32+
LOGGER.info(
33+
"============= Executing GetFlightListingsOperation (One-Way) =========");
34+
35+
36+
37+
GetFlightListingsOperationParams getFlightListingsOperationParams =
38+
GetFlightListingsOperationParams.builder()
39+
.partnerTransactionID("txn-123-4")
40+
.segment1Origin("LAS")
41+
.segment1Destination("FLL")
42+
.segment1DepartureDate(LocalDate.of(2025, 5, 1))
43+
.adult(1)
44+
.senior(1)
45+
.build();
46+
47+
XapClient xapClient = createClient();
48+
49+
FlightSearchResponse flightListingsResponse =
50+
xapClient.execute(new GetFlightListingsOperation(getFlightListingsOperationParams))
51+
.getData();
52+
53+
LOGGER.info("========= GetFlightListingsOperation (One-Way) Executed ========");
54+
55+
if (flightListingsResponse == null || flightListingsResponse.getSegments() == null
56+
|| flightListingsResponse.getSegments().isEmpty()) {
57+
throw new IllegalStateException("No flight found.");
58+
}
59+
60+
61+
LOGGER.info("Transaction ID: {}", flightListingsResponse.getTransactionId());
62+
63+
if (flightListingsResponse.getSegments() != null) {
64+
flightListingsResponse.getSegments().forEach(segment -> {
65+
LOGGER.info("======================== Flight Segment Start ========================");
66+
LOGGER.info("Segment ID: {}", segment.getSegmentId());
67+
LOGGER.info("Flight Duration: {}", segment.getFlightDuration());
68+
LOGGER.info("Total Stops: {}", segment.getTotalStops());
69+
LOGGER.info("Departure Arrival Day Difference: {}",
70+
segment.getDepartureArrivalDayDifference());
71+
LOGGER.info("Seats Left: {}", segment.getSeatsLeft());
72+
LOGGER.info("Fare Type: {}", segment.getFareType());
73+
74+
if (segment.getLegs() != null) {
75+
segment.getLegs().forEach(leg -> {
76+
LOGGER.info("-------------------- Leg Start --------------------");
77+
if (leg.getDepartureAirport() != null) {
78+
LOGGER.info("Departure Airport Code: {}",
79+
leg.getDepartureAirport().getCode());
80+
LOGGER.info("Departure Airport Name: {}",
81+
leg.getDepartureAirport().getName());
82+
LOGGER.info("Departure City: {}",
83+
leg.getDepartureAirport().getCity());
84+
LOGGER.info("Departure Province: {}",
85+
leg.getDepartureAirport().getProvince());
86+
LOGGER.info("Departure Country: {}",
87+
leg.getDepartureAirport().getCountry());
88+
LOGGER.info("Departure Latitude: {}",
89+
leg.getDepartureAirport().getLatitude());
90+
LOGGER.info("Departure Longitude: {}",
91+
leg.getDepartureAirport().getLongitude());
92+
}
93+
if (leg.getArrivalAirport() != null) {
94+
LOGGER.info("Arrival Airport Code: {}",
95+
leg.getArrivalAirport().getCode());
96+
LOGGER.info("Arrival Airport Name: {}",
97+
leg.getArrivalAirport().getName());
98+
LOGGER.info("Arrival City: {}",
99+
leg.getArrivalAirport().getCity());
100+
LOGGER.info("Arrival Province: {}",
101+
leg.getArrivalAirport().getProvince());
102+
LOGGER.info("Arrival Country: {}",
103+
leg.getArrivalAirport().getCountry());
104+
LOGGER.info("Arrival Latitude: {}",
105+
leg.getArrivalAirport().getLatitude());
106+
LOGGER.info("Arrival Longitude: {}",
107+
leg.getArrivalAirport().getLongitude());
108+
}
109+
LOGGER.info("Departure Date Time: {}",
110+
leg.getDepartureDateTime());
111+
LOGGER.info("Arrival Date Time: {}",
112+
leg.getArrivalDateTime());
113+
LOGGER.info("Flight Number: {}",
114+
leg.getFlightNumber());
115+
LOGGER.info("Marketing Airline Code: {}",
116+
leg.getMarketingAirlineCode());
117+
LOGGER.info("Marketing Airline Name: {}",
118+
leg.getMarketingAirlineName());
119+
LOGGER.info("Equipment Code: {}",
120+
leg.getEquipmentCode());
121+
LOGGER.info("Flight On Time Percentage: {}",
122+
leg.getFlightOnTimePercentage());
123+
LOGGER.info("Equipment Name: {}",
124+
leg.getEquipmentName());
125+
LOGGER.info("Flight Duration (Leg): {}",
126+
leg.getFlightDuration());
127+
if (leg.getFlightDistance() != null) {
128+
LOGGER.info("Flight Distance Value: {}",
129+
leg.getFlightDistance().getValue());
130+
LOGGER.info("Flight Distance Unit: {}",
131+
leg.getFlightDistance().getUnit());
132+
}
133+
LOGGER.info("Booking Code: {}",
134+
leg.getBookingCode());
135+
LOGGER.info("Cabin Class: {}",
136+
leg.getCabinClass());
137+
LOGGER.info("Fare Basis Code: {}",
138+
leg.getFareBasisCode());
139+
LOGGER.info("Meal Options: {}",
140+
leg.getMealOptions());
141+
LOGGER.info("Amenities: {}",
142+
leg.getAmenities());
143+
LOGGER.info("---------- Leg End ----------");
144+
});
145+
}
146+
LOGGER.info("=========== Flight Segment End ============");
147+
});
148+
}
149+
150+
if (flightListingsResponse.getOffers() != null) {
151+
flightListingsResponse.getOffers().forEach(offer -> {
152+
LOGGER.info("======================== Flight Offer Start ========================");
153+
154+
if (offer.getLinks() != null) {
155+
offer.getLinks().forEach((key, value) ->
156+
LOGGER.info("Link [{}]: {}", key, value));
157+
}
158+
159+
LOGGER.info("Segment IDs: {}", offer.getSegmentIds());
160+
161+
if (offer.getOfferPrice() != null) {
162+
if (offer.getOfferPrice().getTotalPrice() != null) {
163+
LOGGER.info("Total Price Value: {}",
164+
offer.getOfferPrice().getTotalPrice().getValue());
165+
LOGGER.info("Total Price Currency: {}",
166+
offer.getOfferPrice().getTotalPrice().getCurrency());
167+
}
168+
if (offer.getOfferPrice().getBasePrice() != null) {
169+
LOGGER.info("Base Price Value: {}",
170+
offer.getOfferPrice().getBasePrice().getValue());
171+
LOGGER.info("Base Price Currency: {}",
172+
offer.getOfferPrice().getBasePrice().getCurrency());
173+
}
174+
if (offer.getOfferPrice().getTotalTaxes() != null) {
175+
LOGGER.info("Total Taxes Value: {}",
176+
offer.getOfferPrice().getTotalTaxes().getValue());
177+
LOGGER.info("Total Taxes Currency: {}",
178+
offer.getOfferPrice().getTotalTaxes().getCurrency());
179+
}
180+
if (offer.getOfferPrice().getTotalTaxesAndFees() != null) {
181+
LOGGER.info("Total Taxes and Fees Value: {}",
182+
offer.getOfferPrice().getTotalTaxesAndFees().getValue());
183+
LOGGER.info("Total Taxes and Fees Currency: {}",
184+
offer.getOfferPrice().getTotalTaxesAndFees().getCurrency());
185+
}
186+
if (offer.getOfferPrice().getAveragePricePerTicket() != null) {
187+
LOGGER.info("Average Price Per Ticket Value: {}",
188+
offer.getOfferPrice().getAveragePricePerTicket().getValue());
189+
LOGGER.info("Average Price Per Ticket Currency: {}",
190+
offer.getOfferPrice().getAveragePricePerTicket().getCurrency());
191+
LOGGER.info("Average Price Per Ticket Count: {}",
192+
offer.getOfferPrice().getAveragePricePerTicket().getCount());
193+
}
194+
if (offer.getOfferPrice().getPricePerPassengerCategory() != null) {
195+
offer.getOfferPrice().getPricePerPassengerCategory()
196+
.forEach(categoryPrice -> {
197+
LOGGER.info("---- Passenger Category Price Start ----");
198+
LOGGER.info("Category: {}", categoryPrice.getCategory());
199+
LOGGER.info("Count: {}", categoryPrice.getCount());
200+
if (categoryPrice.getTotalPrice() != null) {
201+
LOGGER.info("Total Price Value: {}",
202+
categoryPrice.getTotalPrice().getValue());
203+
LOGGER.info("Total Price Currency: {}",
204+
categoryPrice.getTotalPrice().getCurrency());
205+
}
206+
if (categoryPrice.getBasePrice() != null) {
207+
LOGGER.info("Base Price Value: {}",
208+
categoryPrice.getBasePrice().getValue());
209+
LOGGER.info("Base Price Currency: {}",
210+
categoryPrice.getBasePrice().getCurrency());
211+
}
212+
if (categoryPrice.getTotalTaxes() != null) {
213+
LOGGER.info("Total Taxes Value: {}",
214+
categoryPrice.getTotalTaxes().getValue());
215+
LOGGER.info("Total Taxes Currency: {}",
216+
categoryPrice.getTotalTaxes().getCurrency());
217+
}
218+
LOGGER.info("---- Passenger Category Price End ----");
219+
});
220+
}
221+
}
222+
223+
224+
LOGGER.info("Ticket Type: {}", offer.getTicketType());
225+
LOGGER.info("======================== Flight Offer End ========================");
226+
});
227+
}
228+
229+
if (flightListingsResponse.getSearchCities() != null) {
230+
flightListingsResponse.getSearchCities().forEach(city -> {
231+
LOGGER.info("======================== Search City Start ========================");
232+
LOGGER.info("City Code: {}", city.getCode());
233+
LOGGER.info("City Name: {}", city.getCity());
234+
LOGGER.info("Province: {}", city.getProvince());
235+
LOGGER.info("Country: {}", city.getCountry());
236+
LOGGER.info("======================== Search City End ========================");
237+
});
238+
}
239+
240+
if (flightListingsResponse.getValidFormsOfPayment() != null) {
241+
flightListingsResponse.getValidFormsOfPayment().forEach((key, value) -> {
242+
LOGGER.info("================= Valid Forms of Payment Start [{}] ============", key);
243+
value.forEach(payment -> {
244+
LOGGER.info("---- Payment Method Start ----");
245+
LOGGER.info("Payment Method: {}", payment.getPaymentMethod());
246+
LOGGER.info("Name: {}", payment.getName());
247+
LOGGER.info("Fee: {}", payment.getFee());
248+
LOGGER.info("Currency: {}", payment.getCurrency());
249+
LOGGER.info("---- Payment Method End ----");
250+
});
251+
LOGGER.info("========== Valid Forms of Payment End [{}] ============", key);
252+
});
253+
}
254+
255+
LOGGER.info(
256+
"===================== End FlightListingsQuickStartScenario ====================");
257+
258+
// --- Example for a Round Trip Search ---
259+
LOGGER.info(
260+
"\n======== Executing GetFlightListingsOperation (Round Trip) ========");
261+
262+
GetFlightListingsOperationParams roundTripParams =
263+
GetFlightListingsOperationParams.builder()
264+
.partnerTransactionID("txn-123-4")
265+
.segment1Origin("EWR")
266+
.segment1Destination("LAX")
267+
.segment1DepartureDate(LocalDate.of(2025, 5, 1))
268+
.segment2Origin("LAX")
269+
.segment2Destination("EWR")
270+
.segment2DepartureDate(LocalDate.of(2025, 5, 5))
271+
.adult(1)
272+
.build();
273+
274+
FlightSearchResponse roundTripResponse =
275+
xapClient.execute(new GetFlightListingsOperation(roundTripParams)).getData();
276+
277+
LOGGER.info(
278+
"========= GetFlightListingsOperation (Round Trip) Executed ==============");
279+
if (roundTripResponse != null && roundTripResponse.getSegments() != null
280+
&& roundTripResponse.getSegments().size() == 2) {
281+
LOGGER.info("Round trip search returned {} segments.",
282+
roundTripResponse.getSegments().size());
283+
}
284+
285+
// --- Example for a Multi-Stop Search ---
286+
LOGGER.info(
287+
"\n========= Executing GetFlightListingsOperation (Multi-Stop) ==========");
288+
289+
GetFlightListingsOperationParams multiStopParams =
290+
GetFlightListingsOperationParams.builder()
291+
.partnerTransactionID("txn-123-4")
292+
.segment1Origin("LAS")
293+
.segment1Destination("ATL")
294+
.segment1DepartureDate(LocalDate.of(2025, 5, 1))
295+
.segment2Origin("ORD")
296+
.segment2Destination("SEA")
297+
.segment2DepartureDate(LocalDate.of(2025, 5, 5))
298+
.adult(1)
299+
.build();
300+
301+
FlightSearchResponse multiStopResponse =
302+
xapClient.execute(new GetFlightListingsOperation(multiStopParams)).getData();
303+
304+
LOGGER.info(
305+
"============ GetFlightListingsOperation (Multi-Stop) Executed ===========");
306+
if (multiStopResponse != null && multiStopResponse.getSegments() != null
307+
&& multiStopResponse.getSegments().size() == 3) {
308+
LOGGER.info("Multi-stop search returned {} segments.",
309+
multiStopResponse.getSegments().size());
310+
}
311+
}
312+
}

0 commit comments

Comments
 (0)