You generally have to give it to your employer by 25 weeks to claim maternity pay but most are lenient on this by a few weeks. You get it from your midwife or GP, if you can't see your midwife for another month then give your GP a ring and ask the receptionist for it, they'll get the GP to do it and you can just collect it.
I don't work so didn't think I needed one, but my DH's HR department asked for it for Paternity leave. I got it at my last hospital appointment. They said you have to be at least 20 weeks. My understanding is you can hand it in to your employer as late as straight after the birth but must have formally requested maternity leave by the specified time limit. I think you can also get them from the GP.