Skip to content

Commit 7333e81

Browse files
author
reejoseph
committed
Flight SDK Example for Listing
1 parent dbf66e4 commit 7333e81

File tree

2 files changed

+315
-2
lines changed

2 files changed

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

0 commit comments

Comments
 (0)