In the games, you get one Masterball during the initial playthrough - and in B2W2, Colress gives you another Masterball postgame. There's also the Join Avenue lottery where you might win them for free.
But has anyone actually used their Masterball(s)? I'm saving them for the last remaining legendaries in case they might be shiny - or basically any shiny that might kill itself.
Though I might never use it ever...XDD