You got to go to Lumiose city and go to Lysandre café (A team flare grunt is standing outside) and defeat the 2 grunts inside (they don´t look like Team flare grunts) and then a secret door opens go in and meet Lysandre and he fights and talks. You got to get the Elevator Key after defeating 2 of the ``Main Flare grunts´´ and you get the Key. You go up and you see a man in cage and Lysandre talks about his past. He is the king from 3.000 years ago and his name is AZ. Then you have to battle Xerosic and when you deafet him you get to choose the button for rescus. Even if you press right he activate the weapon regardless of your wishes. With the weapon starting to activate, you have to go to Team Flare Headquarters which happens to be in Geosenge Town where the weapon and rocks are. When you arrive, you will be joined by your rival and Shauna. Lysandre will apologise for Xerosic not abiding your wishes of not activating the weapon but then state that the world does need changing, and needs to be a world of beauty where things are shared, but where Pokémon don't exist.
Defeat him and he'll give you a chance to find the legendary Pokémon that is being used to power the weapon, but saying it's too late. Rush to the lower floor, defeating Flare grunts and scientists and you'll find Xerneas or Yveltal as part of the machine.
Once captured or defeated, Lysandre will appear and challenge you once more, wanting to take the Legendary Pokémon from you and try again. Once defeated again, Shauna and your rival try to convince Lysandre that the world is a good place and things are to be shared. However, Lysandre makes a declaration that he will grant you all eternal life and activates the weapon. However, the weapon has been reprogrammed and returns its fire in on itself, destroying it once and for all.
Then you can catch Xerneas or Yveltal.
Source: Experience